package com.wuyou.simple;

import com.sun.xml.internal.ws.policy.EffectiveAlternativeSelector;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 2319. 判断矩阵是否是一个 X 矩阵
 */
public class CheckXMatrix {


    public static void main(String[] args) {
        int[][] grid = {{5,0,20}, {0,5,0}, {6,0,2}};
        System.out.println(solution_1(grid));
    }

    public static boolean solution_1(int[][] grid) {
        int index = grid.length - 1;
        for (int i = 0; i < grid.length; i++) {
            for (int j = 0; j < grid[i].length; j++) {
                if (j == index) {
                    index--;
                    if (grid[i][j] == 0) return false;
                }else if(i == j){
                    if (grid[i][j] == 0) return false;
                }else  {
                    if (grid[i][j] != 0) return false;
                }
            }
        }
        return true;
    }
}
